function createElement({name,attr,events,value}){
    if(typeof name !== "string"){
        throw "name is error type"
    }
    let element = document.createElement(name);
    if(value){
        element.innerText = value;
    }
    if(attr && typeof attr === "object"){
        changeElementAttr(element,attr);
    }
    if(events && typeof events === "object"){
        addElementEvent(ele,events);
    }
    return element;
}

function changeElementAttr(ele,attr){
    if(!attr instanceof Object || attr instanceof Array || typeof ele !== "object"){
        return;
    }
    Object.getOwnPropertyNames(attr).forEach(attrname=>{
        let attrData = attr[attrname];
        console.log(attrData,ele);
        if(typeof attrData !== "string" && typeof attrData!=="boolean"){
            changeElementAttr(ele[attrname],attrData);
            return;
        }
        console.log(ele[attrname],attrData,attrname,"赋值了")
        ele[attrname] = attrData;
    });   
}

function addElementEvent(ele,eventList){
    if(typeof eventList !== "object" || !(ele instanceof HTMLElement)){
        return;
    }
    Object.getOwnPropertyNames(eventList).forEach(eventName=>{
        if(typeof eventList[eventName] !== "function"){
            return;
        }
        ele.addEventListener(eventName,eventList[eventName]);
    });
}